import { Component, ElementRef, OnInit, Output, Input, ViewChild, AfterViewInit, EventEmitter } from '@angular/core';
import { HttpModule, Headers, RequestOptions, Http } from '@angular/http';
import { HttpClientModule, HttpClient, HttpErrorResponse } from '@angular/common/http';
import { FormsModule } from '@angular/forms';

import { Service } from '../../../server/server';
import { CudTableService } from '../../../public/serve/cud-table/cud-table.service';
import { addDatatype, roledatas } from '../../institution/institution-add-admin/institution-add-admin.component';
import { Pagination } from '../../../public/serve/pcrudInfo';
declare var $: any;

@Component({
  selector: 'app-management-the',
  templateUrl: './management-the.component.html'
})
export class ManagementTheComponent implements OnInit {

  constructor(private server: Service, private tableListService: CudTableService, ) { }

  ngOnInit() {
    //首次进入接受tree数据
    this.managementtreeidnameeventEmit = this.server.managementtreeidnameeventEmit.subscribe((value: any) => {
      this.superiortheId = value.institutionId;
      //console.log(this.superiortheId)
      this.getTabList(1, 20, this.superiortheId, 2)
    })
  }

  //取消订阅
  public managementtreeidnameeventEmit: any;
  ngOnDestroy() {
    if (this.managementtreeidnameeventEmit) {
      this.managementtreeidnameeventEmit.unsubscribe();
    }
  }

  @Input() superiortheId: any;

  public tabVal: any;

  // 表格
  getTabList(pageNumber, pageSize, id, queryType) {
    let url = this.server.baseUrl+'admin/pusers/getPusersList';
    let data = new Pagination(pageNumber, pageSize, id, queryType);

    this.tableListService.postRequest(url, data).then((data: any) => {
      this.tabVal = data.result;

      //console.log(this.tabVal);
    }).catch();
  }

}
